<?php

namespace app\forms\group;

use app\forms\Model;
use app\validators\PositiveInteger;
use app\models\Group;

/**
 * 组织 父类表单
 */
class BaseForm extends Model
{
    public $id;
    public $parentId;
    public $name;
    public $sort;

    public function rules()
    {
        return [
            ['parentId', PositiveInteger::class],
            ['parentId', 'default', 'value' => 0],
            ['parentId', 'exist', 'targetClass' => Group::class, 'targetAttribute' => 'id'],

            ['name', 'trim'],
            ['name', 'string', 'max' => 32],
            ['name', 'required'],
            ['name', 'unique', 'targetClass' => Group::class],

            ['sort', 'integer'],
            ['sort', 'default', 'value' => 0],
        ];
    }
}